home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DRIVES.SWG / 0070_Get Valid DOS Drives.pas < prev    next >
Pascal/Delphi Source File  |  1994-02-05  |  4KB  |  86 lines

  1. {
  2. Here is my DRIVES routine again to return all valid drive letters on a
  3. PC.  This is a fix from the last version which incorrectly addressed
  4. the local variables and wound up hosing memory.  I also added some
  5. extensive comments for readability.  Enjoy! }
  6.  
  7. {*****************************************************************************
  8.  * Function ...... Drives
  9.  * Purpose ....... To return a string containing the valid drives for the
  10.  *                 current system.
  11.  * Parameters .... None
  12.  * Returns ....... A string of the valid drive letters.
  13.  * Notes ......... Rather than changing to each drive to see if it exists, we
  14.  *                 can instead call DOS Function 26h - Parse a file name.
  15.  *                 If the file name is invalid (eg, F:), then DOS will say
  16.  *                 so.  So, by testing each drive letter as a file name,
  17.  *                 DOS will tell us which are good and which are bad!
  18.  * Author ........ Martin Richardson
  19.  * Date .......... August 6, 1993
  20.  * Update ........ 02-01-94: Corrected problem where local VAR variables were
  21.  *                           not being used, but a random memory location was
  22.  *                           instead!
  23.  *                         : Added comments for clarity.
  24.  *****************************************************************************}
  25. FUNCTION Drives: STRING; ASSEMBLER;
  26. VAR
  27.    DriveInfo:   ARRAY[1..2]  OF CHAR;
  28.    Buffer:      ARRAY[1..40] OF CHAR;
  29.    DriveString: ARRAY[1..25] OF CHAR;
  30. ASM
  31.      PUSH   SI                     { Save Important Registers }
  32.      PUSH   DI
  33.      PUSH   ES
  34.      PUSH   DS
  35.  
  36.      MOV    SI, SS                 { The Stack Segment (SS) points to the }
  37.      MOV    DS, SI                 { VAR's above.  Point DS to it... }
  38.      PUSH   DS
  39.      POP    ES                     { ...and ES as well. }
  40.  
  41.      LEA    SI, DriveInfo          { DS:SI - Where we test each drive letter }
  42.      LEA    DI, Buffer             { ES:DI - FCB Buffer }
  43.      LEA    BX, DriveString        { DS:BX - Our resultant string }
  44.  
  45.      MOV    BYTE PTR [SI], '@'     { The character before 'A' }
  46.      XOR    CX, CX                 { Zero out CX }
  47.  
  48. @Scan:
  49.      INC    BYTE PTR [SI]          { Next Drive Letter }
  50.      MOV    BYTE PTR [SI+1], ':'
  51.      MOV    AX, $2906              { DOS Function 29h - Parse Filename }
  52.      INT    21h                    {   DS:SI - String to be parsed }
  53.                                    {   ES:DI - FCB }
  54.      LEA    SI, DriveInfo          { DS:SI }
  55.      CMP    AL, $FF                { AL = FFh if function fails (invalid }
  56.      JE     @NotValid              {     drive letter) }
  57.  
  58.      INC    CX                     { Add one more to our string length... }
  59.      PUSH   CX                     { ...and save it. }
  60.      MOV    CL, BYTE PTR DS:[SI]   { Grab the valid drive letter... }
  61.      MOV    [BX], CL               { ...and stuff it into our result }
  62.      INC    BX                     { Next position in result string }
  63.      POP    CX                     { Get our length counter back }
  64.  
  65. @NotValid:
  66.      CMP    BYTE PTR [SI], 'Z'     { Did we go through all letters? }
  67.      JNE    @Scan                  { Nope, so next letter }
  68.  
  69.      LEA    SI, DriveString        { Store DriveString to #Result }
  70.      LES    DI, @Result
  71.      INC    DI
  72.      REP    MOVSB
  73.  
  74.      XCHG   AX, DI                 { This is the only way to store the }
  75.      MOV    DI, WORD PTR @Result   {   length that I can get to work. }
  76.      SUB    AX, DI
  77.      DEC    AX
  78.      STOSB
  79.  
  80.      POP    DS                     { Restore Important Registers }
  81.      POP    ES
  82.      POP    DI
  83.      POP    SI
  84. END;
  85.  
  86.